<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .title{
            float: left;
            cursor: pointer;
            padding: 5px 20px;
            border: 1px solid #ccc;
            border-top-left-radius: 4px;
            border-top-right-radius: 4px;
            background-color: orange;
            color: honeydew;
        }
        .active{
            background-color: plum;
            border-bottom: 1px solid transparent;
        }
        .clear{
            clear: both;
        }
        #content{
            width: 500px;
            height: 500px;
            padding: 10px;
            position: relative;
            top: -2px;
            z-index: -1;
            border: 1px solid #ccc;
            background: linear-gradient(to bottom,plum,#ffffff);
        }
        .input{
            display: block;
            width: 300px;
            height: 40px;
            line-height: 40px;
            margin: 0 auto;
            border-radius: 6px;
            border: 1px solid plum;
            padding-left: 20px;
            font-size: 18px;
            color: #666;
            outline: none;
        }
    </style>
</head>
<body>
    <input type="text" class="input" placeholder="请输入音乐ID" autofocus>
    <div class="title song active">单曲</div>
    <div class="title lyric">歌词</div>
    <div class="title playlist">其他</div>
    <div class="clear"></div>
    <div id="content"></div>
    <script src="./js/jquery-3.3.1.min.js"></script>
    <script>
        var contentList=[];
        let indexPage=`这是首页的内容`;
        let newsPage=`这是新闻的内容`;
        let musicPage=`这是音乐的内容`;
        contentList.push(indexPage,newsPage,musicPage);
        //默认显示首页内容
        content.innerHTML=contentList[0]

        //选中按钮
        let btns= document.querySelectorAll('.title');

        //获取当前选中的元素
        let currentBtns=btns[0]

        for(let i=0;i<btns.length;i++){
            //通过for循环给每一个按钮增加属性并绑定事件
            let obj=btns[i];
            //新增btnIndex属性，作为编号
            obj.btnIndex=i;
            //绑定单击事件
            obj.onclick=function(e){
                //替换对应的内容
                content.innerHTML=contentList[e.target.btnIndex];
                //移除class
                currentBtns.classList.remove('active');
                // e.target.classList.add('active');
                //给当前元素增加class
                this.classList.add('active');
                //更新当前元素
                currentBtns=e.target
            }
        }

        
    </script>
</body>
</html>